/*
 * @(#)TaskTreeContentsProvidor.java.java        0.00 2007/12/24
 */
package jp.ekasi.pms.ui.grid.providor;

import jp.ekasi.pms.model.ModelPackage;
import jp.ekasi.pms.model.Task;

import org.eclipse.emf.common.notify.AdapterFactory;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.emf.edit.provider.ViewerNotification;

/**
 * @author sumari.rutao@gamil.com
 */
public class TaskTreeContentsProvidor extends AbstractTreeContentsProvidor {

	public TaskTreeContentsProvidor(AdapterFactory adapterFactory) {
		super(adapterFactory);
	}

	@Override
	protected EReference getChildrenFeature() {
		return ModelPackage.Literals.TASK__SUB_TASKS;
	}
	
	@Override
	public Object getParent(Object object) {
		
		Task task = (Task)object;		
		if(task.getSummaryTask()==null) {
			return task.getSummaryTask();
		}
		
		return task.eContainer();
	}
	
	@Override
	public void notifyChanged(Notification notification) {
		updateChildren(notification);

		switch (notification.getFeatureID(Task.class)) {
			case ModelPackage.TASK__UID:
			case ModelPackage.TASK__ID:
			case ModelPackage.TASK__WBS:
			case ModelPackage.TASK__NAME:
			case ModelPackage.TASK__START:
			case ModelPackage.TASK__FINISH:
			case ModelPackage.TASK__DURATION:
			case ModelPackage.TASK__EFFORT:
			case ModelPackage.TASK__PRIORITY:
			case ModelPackage.TASK__ACTUAL_START:
			case ModelPackage.TASK__ACTUAL_FINISH:
			case ModelPackage.TASK__ACTUAL_DURATION:
			case ModelPackage.TASK__MEMO:
			case ModelPackage.TASK__RESOURCES:
			case ModelPackage.TASK__MILESTONE:
			case ModelPackage.TASK__SUB_TASKS:
			case ModelPackage.TASK__SUMMARY:
			case ModelPackage.TASK__SUMMARY_TASK:
				fireNotifyChanged(new ViewerNotification(notification, notification.getNotifier(), false, true));
				return;
		}
		super.notifyChanged(notification);
	}
}
